<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>发布需求</title>
    <header th:replace="header::html"></header>


</head>
<body>
<form class="layui-form " action="">
    <!--    下拉框-->
    <!--<div class="layui-form layui-form-pane demoTable" sytle="float:center">-->

    <div class="layui-inline">
        <label class="layui-form-label">请选择类型</label>
        <div class="layui-input-inline">
            <!--            一级-->

            <select name="sname" id="ntype" lay-filter="typeAAA" lay-verify="typeAA" >
            </select>

        </div>

<!--        <div class="layui-input-inline">-->
<!--            &lt;!&ndash;            二级&ndash;&gt;-->

<!--            <select name="status" id="status" lay-filter="status" lay-verify="status">-->
<!--            </select>-->
<!--        </div>-->
    </div>
    <!--</div>-->

    <!--    请输入您的标题-->
    <div class="layui-form-item">
        <label class="layui-form-label">请输入标题</label>
        <div class="layui-input-block">
            <input type="text" name="ntitle" lay-verify="ntitle" autocomplete="off" placeholder="请输入标题"
                   class="layui-input" style="width: 70%">
        </div>
    </div>

    <!--    发布的内容-->
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">发布的内容</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" name="ncontent" lay-verify="ncontent" class="layui-textarea"
                      style="width: 70%"></textarea>
        </div>
    </div>


    <!--    要求-->
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">要求</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入要求" name="ndemand" lay-verify="ndemand" class="layui-textarea"
                      style="width: 70%"></textarea>
        </div>
    </div>
    <!--金钱-->
    <div class="layui-form-item">
        <label class="layui-form-label">佣金</label>
        <div class="layui-input-inline">
            <input type="text" name="nmoney" lay-verify="nmoney" placeholder="请输入价格" autocomplete="off"
                   class="layui-input" onkeyup="value=value.match(/^-?[0-5]\d*$/)||value.match(/-?/)">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">截止发布时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="nendtime" id="test2" placeholder="yyyy-MM-dd" lay-verify="nendtime">
            </div>
        </div>
    </div>


    <!--工期-->
    <div class="layui-form-item">
        <label class="layui-form-label">时间</label>
        <div class="layui-input-inline">
            <input type="text" name="nrealtime" lay-verify="nrealtime" placeholder="要求时间" autocomplete="off"
                   class="layui-input" onkeyup="value=value.match(/^-?[0-9]\d*$/)||value.match(/-?/)">
        </div>
    </div>


    <!--    发布按钮-->
    <div class="layui-form-item" style="margin-left: 110px">
        <button class="layui-btn" lay-submit="" lay-filter="release" lay-verify="release">发布</button>
    </div>


</form>


</body>
<script>


	layui.use(['form', 'layer', 'laydate'], function () {
		$ = layui.jquery;
		var form = layui.form
			, layer = layui.layer
			, laydate = layui.laydate;

		// 一级
		$(function () {
			$.ajax({
				url: "/api-front/user/sparentid",
				data: {},
				dataType: "json",
				success: function (results) {
					$("#ntype").empty();

					if (results != 0) {
						$("#ntype").append(new Option("---请选择---", ""));
						$.each(results, function (index, item) {
							$('#ntype').append(new Option(item.sname, item.sid));

						});
					} else {
						$("#ntype").append(new Option("暂无数据", ""));

					}

					layui.form.render("select");
				}
			});
			//二级
			//select 监听
			// form.on('select(typeAAA)', function (data) {
			// 	var value = data.value;  //select选中的值
			// 	$.ajax({
			// 		url: "/api-front/user/sony?Id=" + value,
			// 		dataType: "json",
			// 		success: function (Number) {
			// 			$("#status").empty();
            //
			// 			if (Number != 0) {
			// 				$("#status").append(new Option("---请选择---", ""));
			// 				$.each(Number, function (index, item) {
			// 					$('#status').append(new Option(item.sname, item.sid));
			// 				});
			// 			}
            //
			// 			else{
			// 				$("#status").append(new Option("暂无数据", ""));
            //             }
            //
			// 			layui.form.render("select");
			// 		}
			// 	})
			// })
		});

		//自定义验证规则
		form.verify({
			uname: function (value) {
				if (value.length < 3) {
					return '昵称至少得5个字符啊';
				}
			}
			, nmoney: function (value) {
				if (value.length <=0 ||value.length>6) {
					return '请把价格控制在6位数以内';
				}
			}
			, nrealtime: [/^30$|^(\d|[1-9]\d)(\.\d+)*$/, '时间必须大于0小于30']
			, ntitle: function (value) {
				if (value.length <= 0 || value.length >= 15) {
					return '郭文忠小哥哥提示您:标题应该在1到15个字之间，么么哒！';
				}
			}
			, ncontent: function (value) {
				if (value.length <= 0 || value.length >= 100) {
					return '郭文忠小哥哥提示您:请把内容控制在1到100个字之间，么么哒！';
				}
			}
			, ndemand: function (value) {
				if (value.length <= 0 || value.length >= 50) {
					return '郭文忠小哥哥提示您:请把要求控制在1到50个字之间，么么哒！';
				}
			}
			, nendtime: function (value) {
				if (value.length <= 0 ) {
					return '请填写截止发布的时间';
				}
			}
			, typeAA: function (value) {
				if (value.length <= 0 ) {
					return '请选择你要的类型';
				}
			}
			, status: function (value) {
				if (value.length <= 0 ) {
					return '请选择你要的类型';
				}
			}

		});


		//监听提交
		form.on('submit(release)', function (data) {
			$.ajax({
				url: "/api-front/user/pub",
				type: "POST",
				data: data.field,
				dataType: 'json',
				success: function (result) {
					if (result.code == 5000102) {
						layer.alert(result.msg);
						top.window.location.href = "/api-front/getPage?pageName=frontPage/user-login";

					} else {
						layer.alert("发布成功", {icon: 6}, function () {
							//关闭当前frame
							xadmin.close();
							// xadmin.father_reload();
							top.window.location.href = "/api-front/getPage?pageName=frontPage/personal";


						});
					}
				}
			});
			return false;
		});


		//开始时间
		laydate.render({
			elem: '#test1',
			min: 0　　//设置最小开始时间
		});

		//截止时间
		laydate.render({
			elem: '#test2',
			min: 0　　//设置最小开始时间
		});


	});

</script>

</html>